import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';

class OpenBigImagePage extends StatefulWidget {
  String url;
  double width;
  double height;

  OpenBigImagePage(this.url, this.width, this.height);

  @override
  _OpenBigImagePageState createState() => _OpenBigImagePageState();
}

class _OpenBigImagePageState extends State<OpenBigImagePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
      ),
      body: Stack(
        children: [
          Positioned(
            child: PhotoView(
              imageProvider: NetworkImage(
                widget.url,
              ),
              loadingBuilder: (context, event) {
                if (event == null) {
                  return const Center(
                    child: Text("Loading"),
                  );
                }
                final value = event.cumulativeBytesLoaded /
                    (event.expectedTotalBytes ?? event.cumulativeBytesLoaded);

                final percentage = (100 * value).floor();
                return Center(
                  child: Text("$percentage%"),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
